<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
    <title>已添加专家</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>

    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>已添加专家</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">采购项目管理</a></li>
            <li class="active"><a href="#">专家数</a></li>
        </ol>
    </section>
     <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                    <div class="form-group form-group-xs">
                     <label>编码：</label>
                        <input class="form-control" type="text" id="expertCode" placeholder="编码" />
                    </div>
                     <div class="form-group form-group-xs">
                        <label>姓名：</label>
                        <input class="form-control" type="text" id="name" placeholder="姓名" />
                    </div>
                    <div class="form-group form-group-xs">
                        <label>性别：</label>
                        <input class="form-control" type="text" id="sex" placeholder="性别" />
                    </div>
                    <div class="form-group form-group-xs">
                        <label>工作单位：</label>
                        <input class="form-control" type="text" id="companyId" placeholder="工作单位" />
                    </div>
                    
                    
                    <button type="button" class="btn btn-success btn-sm" onclick="search()">查  询</button>
                </div>
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
        	 <label class="btn btn-default btn-sm" onclick="batchChangeStatus(1)">启用</label>
             <label  class="btn btn-default btn-sm" onclick="batchChangeStatus(0)">停用</label>
             <a href="toList.html" class="btn btn-default btn-sm" >返回</a>
        </div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    
    
  //查询
	function search() {
		var expertCode = $("#expertCode").val();
		var name = $("#name").val();
		var sex = $("#sex").val();
		var companyId = $("#companyId").val();
		$("#gridlist").jqGrid("clearGridData");
			$("#gridlist").jqGrid('setGridParam',{  
			url:"${ctx}/bidProject/getHaveAddDrugDataList.html",
			mtype: "POST",
	        datatype:'json',
	        postData:{
	        	"expertCode":expertCode,
	        	"name":name,
	        	"sex":sex,
	        	"companyId":companyId},
	        page : 1
	    }).trigger("reloadGrid"); //重新载入  
	}
        $(function () {
            
            $("#gridlist").jqGrid({
                url: "getHaveAddDrugDataList.html",
                mtype: "POST",
                postData: { "projId" : "${projId}"},
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: ['expertId','编码', '姓名','性别', '身份证号', '工作单位','状态'],
                colModel: [
					{ name: 'expertId', width: 100,hidden:true , align:"center",sortable: false},
                    { name: 'expertCode', width: 100 , align:"center",sortable: false},
                    { name: 'name', width: 100 , align:"center" ,sortable: false},
                    { name: 'sex', width: 100 , align:"center" ,sortable: false},
                    { name: 'idNum', width: 100 , align:"center" ,sortable: false},
                    { name: 'companyId', width: 100 , align:"center" ,sortable: false},
                    { name: 'status', width : 30, align : 'center', sortable : false,
                	formatter : function(val, opts, rowdata) {
						if (rowdata.status == 1 ) {
							return "启用";
						} else if (rowdata.status == 0) {
							return "停用";
						}
					}}
                ],
                
                rowNum: 10,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "${name}-已添加专家 ",
                jsonReader: {
                    repeatitems: false,
                    id: "expertId"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });


        function batchSubmitDrugTOProj(){
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];

            if (rowIds.length <= 0) {
                $.HN.message.alert("请选择要操作的行！", "消息", "error");
                return;
            }
            var list = [];
            for (var i=0; i<rowIds.length; i++) {
                rowId = rowIds[i];
                list.push({"expertId":rowId,"projId":'${bidProject.projId}'});
            }
            submitDrugTOProj(JSON.stringify(list));
        }
        
        
        function submitDrugTOProj(list){
            $.ajax({
                type:"POST",
                url:"batchSubmitDrugTOProj.html",
                data:{"expertId":list},
                dataType:"json",
                success:function(returnData){
                    if (returnData.success == true) {
                        $("#gridlist").jqGrid("clearGridData");
                        $("#gridlist").jqGrid().trigger("reloadGrid");
                        $.HN.message.alert("添加药品成功！", "消息", "success");
                    } else {
                        $.HN.message.alert("添加药品失败！", "消息", "error");
                    }
                }
            });
            
        }
        //启用禁用
         function changeStatus(id, status) {
            $.ajax({
            	 type:"POST",
                 url:"${ctx}/bidProject/changeStatus.html",
                 data:{"expertId":id,"status":status},
                 dataType:"json",
                 success: function(result) {
                     if (result) {
                         $.HN.message.alert("保存成功！", "消息", "success");
                     	$("#gridlist").jqGrid('setGridParam',{  
                	        datatype:'json'
                	    }).trigger("reloadGrid");
                     } else {
                         $.HN.message.alert("保存失败！", "消息", "error");
                     }
                 }
            });
        } 
        //批量启用、停用
         function batchChangeStatus(status) {
        	 var msg = "";
 			if (status == "0") {
 				msg = "停用";
 			} else if (status == "1") {
 				msg = "启用";
 			}
             var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
             if (rowIds.length <= 0) {
                 $.HN.message.alert("请选择要操作的行！", "消息", "error");
                 return;
             }
             $.HN.message.confirm('确定'+msg+'吗？', '', '').on(function (e) {
        		 if(e){
             var list = [];
             for (var i=0; i<rowIds.length; i++) {
            	 var rowdata = $("#gridlist").jqGrid(
							'getRowData', rowIds[i]);
                 rowId = rowdata.expertId;
                 list.push({"expertId":rowId, "status":status});
             }
             $.post("${ctx}/bidProject/batchChangeStatus.html", {
                 "array" : json.jsonToString(list)
             }, function(result) {
                 if (result) {
                     $.HN.message.alert("操作成功！", "消息", "success");
                     $("#gridlist").jqGrid('setGridParam',{  
             	        datatype:'json'
             	    }).trigger("reloadGrid");
                 } else {
                     $.HN.message.alert("操作失败！", "消息", "error");
                 }
             }, "json")
		      }
				 
			 });
         }

         
    </script>
</body>
</html>